//
//  HMWelcomeController.swift
//  HMSlender
//
//  Created by 赵少朋赵少朋 on 17/1/26.
//  Copyright © 2017年 ITheima. All rights reserved.
//

import UIKit
import SDWebImage

class HMWelcomeController: UIViewController {

    
    //在视图开始加载的时候设置背景
    override func loadView() {
        
        view = bg_view
    }
    var iconView:UIImageView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.iconView = icon_view
        guard let i = iconView else {
            return
        }
        view.addSubview(i)
        i.snp_makeConstraints { (make) in
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
            make.size.equalTo(CGSize(width: 90, height: 90))
        }
        let nameLb = nameLabel
        view.addSubview(nameLb)
        nameLb.snp_makeConstraints { (make) in
            make.top.equalTo(i.snp_bottom).offset(16)
            make.centerX.equalTo(i)
        }
        
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private lazy var bg_view:UIImageView =  {
        
        return UIImageView(image: UIImage(named: "ad_background"))
    }()
    
    private lazy var icon_view: UIImageView = {
    
        let v = UIImageView()
        let imgPath = HMOAuthModel.shared.userAccountModel?.avatar_large
        let url = URL(string: imgPath ?? "")
        v.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default"))
        v.layer.cornerRadius = 45
        v.layer.masksToBounds = true
        //增加圆角边框
        v.layer.borderWidth = 1
        v.layer.borderColor = themeColor.cgColor
        return v
    }()
    private lazy var nameLabel:UILabel = {
    
        let lab = UILabel()
        lab.text = HMOAuthModel.shared.userAccountModel?.screen_name
        lab.textAlignment = .center
        lab.font = UIFont.systemFont(ofSize: midTextFont)
        return lab
    }()
    
    override func viewDidAppear(_ animated: Bool) {
        //一定要记得调用
        super.viewDidAppear(animated)
        
        self.iconView?.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
            
        }
        
        UIView.animate(withDuration: 2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {()->() in
        
            //要做动画必须立即刷新UI
            self.view.layoutIfNeeded()
        }, completion: {(_)->() in
        
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: SETROOTVIEW), object: nil)
        })
        
        
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
